﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace BMUpload.Utility
{
    /// <summary>
    /// 系统操作日志类
    /// </summary>
    public  class SysLog
    {
        //public string path;
        public SysLog()
        {
            //path =Common.GetAppPath() + "KingbosErr.log";
        }
        /// <summary>
        /// 写日志，默认文件名为KBLog.log
        /// </summary>
        /// <param name="strmessage"></param>
        public static void WriteLocalLog(string strmessage)
        { WriteLocalLog(strmessage, "BMLog.log"); }
        /// <summary>
        /// 写日志并指定本地文件名
        /// </summary>
        /// <param name="strmessage"></param>
        /// <param name="filename"></param>
        public static void WriteLocalLog(string strmessage,string filename)
        {
            string logpath = Common.GetAppPath();
            string logFilePath = logpath + filename;
            try
            {
                if (!File.Exists(logFilePath)) File.Create(logFilePath).Close();
            
                using (StreamWriter sw = File.AppendText(logFilePath))
                {
                    sw.WriteLine("{0}", DateTime.Now.ToString() + "\t" + strmessage);
                    sw.Flush();
                    sw.Close();
                }
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 写错误日志到本地文件
        /// </summary>
        /// <param name="strmessage"></param>
        public static void WriteLocalErrLog(string strmessage)
        {
            WriteLocalLog(strmessage, "BMErrLog.log"); 
        }
    }
}
